package com.zhang.sys;

import com.ygdk.util.ListUtil;
import com.ygdk.util.StringUtil;
import com.zhang.BaseHibernateDAO;
import com.zhang.bean.GisSysConditionBean;

import java.util.ArrayList;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

/**
 * A data access object (DAO) providing persistence and search support for
 * SysModule entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see com.zhang.sys.SysModule
 * @author MyEclipse Persistence Tools
 */

public class SysModuleDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(SysModuleDAO.class);
	// property constants
	public static final String TEXT = "text";
	public static final String ACTIVE = "active";
	public static final String SORT_ORDER = "sortOrder";
	public static final String CLSS_NAME = "clssName";
	public static final String ICON_CLS = "iconCls";
	public static final String DIRECTORY = "directory";
	public static final String FILE_NAME = "fileName";
	public static final String FATHORID = "fathorid";
	
	public void save(SysModule transientInstance) {
		log.debug("saving SysModule instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(SysModule persistentInstance) {
		log.debug("deleting SysModule instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public SysModule findById(java.lang.String id) {
		log.debug("getting SysModule instance with id: " + id);
		try {
			SysModule instance = (SysModule) getSession().get(
					"com.zhang.sys.SysModule", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(SysModule instance) {
		log.debug("finding SysModule instance by example");
		try {
			List results = getSession().createCriteria(
					"com.zhang.sys.SysModule").add(Example.create(instance))
					.list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding SysModule instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from SysModule as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByText(Object text) {
		return findByProperty(TEXT, text);
	}

	public List findByFathorid(Object fathorid) {
		return findByProperty(FATHORID, fathorid);
	}
	
	public List findByActive(Object active) {
		return findByProperty(ACTIVE, active);
	}

	public List findBySortOrder(Object sortOrder) {
		return findByProperty(SORT_ORDER, sortOrder);
	}

	public List findByClssName(Object clssName) {
		return findByProperty(CLSS_NAME, clssName);
	}

	public List findByIconCls(Object iconCls) {
		return findByProperty(ICON_CLS, iconCls);
	}

	public List findByDirectory(Object directory) {
		return findByProperty(DIRECTORY, directory);
	}

	public List findByFileName(Object fileName) {
		return findByProperty(FILE_NAME, fileName);
	}

	public List findAll() {
		log.debug("finding all SysModule instances");
		try {
			String queryString = "from SysModule";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public SysModule merge(SysModule detachedInstance) {
		log.debug("merging SysModule instance");
		try {
			SysModule result = (SysModule) getSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(SysModule instance) {
		log.debug("attaching dirty SysModule instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(SysModule instance) {
		log.debug("attaching clean SysModule instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
	
	public List findAllActiveSortDesc() {
		log.debug("finding all SysModule instances");
		try {
			String queryString = "from SysModule kqxx where kqxx.active='1' order by kqxx.sortOrder desc";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}
	
	public List findByActiveAndSortDesc(String active,String fathorid) {
		log.debug("finding all SysModule instances");
		try {
			String queryString = "from SysModule kqxx where kqxx.active=:active and kqxx.fathorid=:fathorid order by kqxx.sortOrder desc";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter("active", active);
			queryObject.setParameter("fathorid", fathorid);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}
	
	public List findAllSortDesc() {
		log.debug("finding all SysModule instances");
		try {
			String queryString = "from SysModule kqxx order by kqxx.sortOrder desc";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}
	public static void main(String[] args) {
		SysModuleDAO dao = new SysModuleDAO();
		dao.findByActiveAndSortDesc("0", "0");
	}
}